var nowPage = 0;
var projectListId = 0;
var projectListType = 0;
var projectListPlan = "";
var projectListHistory = 0;
var projectList = {
	getData : function(id, type) {
		projectListId = id;
		projectListType = type;
		projectListPlan = $("[name='plan']:checked").val();
		_projectListGetData = $("#pageShow").myPagination({
			currPage : 1,
			pageCount : 10,
			pageNumber : 5,
			panel : {
				tipInfo_on : true,
				links : "javascript:void()"
			},
			ajax : {
				onClick : function(page) {
					ZENG.msgbox.show(" 正在加载" + page + "页，请稍后...", 6, 600);
					nowPage = page;
				},
				on : true,
				async : false,
				type : "POST",
				dataType : 'json',
				url : "/app/project!getProjectsByCategory",
				param : {
					"c_id" : projectListId,
					"type" : projectListType,
					"plan" : projectListPlan
				},
				callback : function(data) {
					backUrl.addCookie(data.state);
					if ('success' == data.state) {
						// if (null != data.msg && 0 != data.msg.length) {
						pageCountId = data.pageCount;// 获取总页数
						// } else {
						// data.pageCount = 0;
						// pageCountId = data.pageCount;
						// }
						projectList.createContent(data.msg);
					} else if (data.state == "error") {
						errorAlert(data.msg);
					}
				}
			}
		});
	},
	createContent : function(data) {
		var pm = $("#createContent");
		var content = "";
		pm.empty();
		$(".tip-darkgray").remove();
		if (data != null && data.length != 0) {
			$("#pageShow").show();
			content = "<tr id='titleTr'><th width='30%' scope='col'>项目名称</th><th width='10%' scope='col'>实施时间</th>"
					+ "<th width='10%' scope='col'>总投资（亿）</th><th width='15%' scope='col'>主管部门</th>"
					+ "<th width='20%' scope='col'>资金来源</th><th width='10%' scope='col'>批注</th>"
					+ "<th width='5%' scope='col'>操作</th></tr>";
			for ( var int = 0; int < data.length; int++) {
				var v = data[int];
				var id = v.id;
				var name = v.name;
				var fund = v.fund;
				var impl = v.impl_time;
				var fundPlan = v.fund_plan;
				var mgrDepart = v.mgr_depart;
				var comment = v.comment;
				var checkout = v.checkout;
				var _name = name;
				if (name.length > 21) {
					name = name.substring(0, 19) + "...";
				}
				var _fundPlan = fundPlan;
				if (fundPlan.length > 15) {
					fundPlan = fundPlan.substring(0, 13) + "...";
				}
				var _mgrDepart = mgrDepart;
				if (null != mgrDepart && "" != mgrDepart && mgrDepart.length > 13) {
					mgrDepart = mgrDepart.substring(0, 11) + "...";
				}
				var _comment = "";
				if (Number(comment) == 2) {
					_comment = "<img src='/img/comment.png'>";
				} else {
					_comment = "-";
				}
				if (Number(checkout) == 1) {
					content += "<tr class='checkout'>";
				} else {
					content += "<tr>";
				}

				if (null == fund || typeof (fund) == "undefined") {
					fund = "";
				}
				if (null == mgrDepart || typeof (mgrDepart) == "undefined") {
					mgrDepart = "";
				}
				if (null == fundPlan || typeof (fundPlan) == "undefined") {
					fundPlan = "";
				}

				content += "<td align='center'><a href='/app/project!getProjectDetailedById?p_id=" + id
						+ "' target='_blank' title='" + _name + "' class='tempClass'>" + name
						+ "</a></td><td align='center'>" + impl + "</td><td align='center'>" + fund
						+ "</td><td align='center' title='" + _mgrDepart + "'>" + mgrDepart
						+ "</td><td align='center' title='" + _fundPlan + "'>" + fundPlan + "</td><td align='center'>"
						+ _comment + "</td><td align='center'><a href='javascript:projectNotation.show(" + id
						+ ")'>批示</a></td></tr>";
			}
		} else {
			$("#pageShow").hide();
			content = "<tr id='noData'><td align='center'><h1>暂无数据</h1></td></tr>";
		}
		pm.append(content);
		projectListPoshytip();
	},
	jumpPage : function() {// 分页跳转
		_projectListGetData.jumpPage(nowPage);
	}
};
function projectListPoshytip() {
	$("#createContent").find("td").poshytip({
		className : 'tip-darkgray',
		showOn : 'hover',
		alignTo : 'target',
		alignX : 'center',
		alignY : "center",
		allowTipHover : true,
		fade : true,
		slide : true
	});
	$(".tempClass").poshytip({
		className : 'tip-darkgray',
		showOn : 'hover',
		alignTo : 'target',
		alignX : 'right',
		alignY : "center",
		offsetX : 10,
		allowTipHover : true,
		fade : true,
		slide : true
	});
};
/**
 * 点击左侧类别树后执行的该方法
 * 
 * @param id
 * @param type
 */
function categoryClickProjectSearch(id, type) {
	$("#category").removeAttr("checked");
	projectList.getData(id, type);
}
/**
 * 批示后跳转的方法
 */
function projectNotationJump() {
	projectList.jumpPage();
}
var onloadProjectList = {
	onload : function() {
		$("#category").click(function() {
			var tof = $("#category").is(":checked");
			if (tof == true) {
				projectListId = 0;
				projectListType = 0;
				$("#store").find("ul").slideUp();
				$("#store").find(".sz_nav_left_xz").removeClass("sz_nav_left_xz");
				$("#store").find(".jian").removeClass("jian").addClass("jia");
				projectList.getData(projectListId, projectListType);
			} else {
				var num = getUrlParam("type");
				if (checkValue2(num)) {
					$("#store").children("li").eq(num).find("a").click();
				}
			}
		});

		var num = getUrlParam("type");
		if (checkValue2(num)) {
			$("#store").children("ul").slideDown();
			$("#store").children("ul").eq(0).children("li").eq(num).find("a").click();
		} else {
			$("#category").prop("checked", true);
			// $("#category").click();
		}
		$("[name='plan']").click(function() {
			projectList.getData(projectListId, projectListType);
		});
		var plan = getUrlParam("plan");
		if (checkValue2(plan)) {
			var v = $(".sz_nr_right_top").find("input");
			if (Number(plan) <= 3) {
				v.eq(plan).attr("checked", "checked");
				v.eq(plan).click();
			}

			// switch (Number(plan)) {
			// case 0:
			// v.eq(plan).attr("checked", "checked");
			// v.eq(plan).click();
			// break;
			// case 1:
			// v.eq(plan).attr("checked", "checked");
			// v.eq(plan).click();
			// break;
			// case 2:
			// v.eq(plan).attr("checked", "checked");
			// v.eq(plan).click();
			// break;
			// case 3:
			// v.eq(plan).attr("checked", "checked");
			// v.eq(plan).click();
			// break;
			// }
		}
	}
};